| Description | Tests | Scoring | ||||||
|---|---|---|---|---|---|---|---|---|
| Pass | Fail | Error | Unkn. | Man. | Score | Max | Percent | |
| 1 Initial Setup | 23 | 19 | 0 | 0 | 7 | 23.0 | 42.0 | 55% |
| 1.1 Filesystem Configuration | 12 | 9 | 0 | 0 | 3 | 12.0 | 21.0 | 57% |
| 1.1.1 Disable unused filesystems | 0 | 6 | 0 | 0 | 0 | 0.0 | 6.0 | 0% |
| 1.2 Configure Software Updates | 0 | 0 | 0 | 0 | 2 | 0.0 | 0.0 | 0% |
| 1.3 Filesystem Integrity Checking | 0 | 2 | 0 | 0 | 0 | 0.0 | 2.0 | 0% |
| 1.4 Secure Boot Settings | 1 | 3 | 0 | 0 | 0 | 1.0 | 4.0 | 25% |
| 1.5 Additional Process Hardening | 2 | 1 | 0 | 0 | 1 | 2.0 | 3.0 | 67% |
| 1.6 Mandatory Access Control | 1 | 2 | 0 | 0 | 0 | 1.0 | 3.0 | 33% |
| 1.6.1 Configure AppArmor | 1 | 2 | 0 | 0 | 0 | 1.0 | 3.0 | 33% |
| 1.7 Command Line Warning Banners | 4 | 2 | 0 | 0 | 0 | 4.0 | 6.0 | 67% |
| 1.8 GNOME Display Manager | 3 | 0 | 0 | 0 | 0 | 3.0 | 3.0 | 100% |
| 2 Services | 23 | 2 | 0 | 0 | 2 | 23.0 | 25.0 | 92% |
| 2.1 Special Purpose Services | 18 | 1 | 0 | 0 | 1 | 18.0 | 19.0 | 95% |
| 2.1.1 Time Synchronization | 3 | 0 | 0 | 0 | 1 | 3.0 | 3.0 | 100% |
| 2.2 Service Clients | 5 | 1 | 0 | 0 | 0 | 5.0 | 6.0 | 83% |
| 3 Network Configuration | 7 | 27 | 0 | 0 | 6 | 7.0 | 34.0 | 21% |
| 3.1 Disable unused network protocols and devices | 1 | 0 | 0 | 0 | 0 | 1.0 | 1.0 | 100% |
| 3.2 Network Parameters (Host Only) | 0 | 2 | 0 | 0 | 0 | 0.0 | 2.0 | 0% |
| 3.3 Network Parameters (Host and Router) | 1 | 8 | 0 | 0 | 0 | 1.0 | 9.0 | 11% |
| 3.4 Uncommon Network Protocols | 0 | 0 | 0 | 0 | 0 | 0.0 | 0.0 | 0% |
| 3.5 Firewall Configuration | 5 | 17 | 0 | 0 | 6 | 5.0 | 22.0 | 23% |
| 3.5.1 Configure UncomplicatedFirewall | 1 | 4 | 0 | 0 | 2 | 1.0 | 5.0 | 20% |
| 3.5.2 Configure nftables | 1 | 7 | 0 | 0 | 2 | 1.0 | 8.0 | 12% |
| 3.5.3 Configure iptables | 3 | 6 | 0 | 0 | 2 | 3.0 | 9.0 | 33% |
| 3.5.3.1 Configure iptables software | 2 | 1 | 0 | 0 | 0 | 2.0 | 3.0 | 67% |
| 3.5.3.2 Configure IPv4 iptables | 0 | 3 | 0 | 0 | 1 | 0.0 | 3.0 | 0% |
| 3.5.3.3 Configure IPv6 ip6tables | 1 | 2 | 0 | 0 | 1 | 1.0 | 3.0 | 33% |
| 4 Logging and Auditing | 1 | 8 | 0 | 0 | 3 | 1.0 | 9.0 | 11% |
| 4.1 Configure System Accounting (auditd) | 0 | 0 | 0 | 0 | 0 | 0.0 | 0.0 | 0% |
| 4.1.1 Ensure auditing is enabled | 0 | 0 | 0 | 0 | 0 | 0.0 | 0.0 | 0% |
| 4.1.2 Configure Data Retention | 0 | 0 | 0 | 0 | 0 | 0.0 | 0.0 | 0% |
| 4.2 Configure Logging | 0 | 8 | 0 | 0 | 2 | 0.0 | 8.0 | 0% |
| 4.2.1 Configure rsyslog | 0 | 4 | 0 | 0 | 2 | 0.0 | 4.0 | 0% |
| 4.2.2 Configure journald | 0 | 3 | 0 | 0 | 0 | 0.0 | 3.0 | 0% |
| 5 Access, Authentication and Authorization | 17 | 29 | 0 | 0 | 1 | 17.0 | 46.0 | 37% |
| 5.1 Configure time-based job schedulers | 1 | 8 | 0 | 0 | 0 | 1.0 | 9.0 | 11% |
| 5.2 Configure sudo | 1 | 2 | 0 | 0 | 0 | 1.0 | 3.0 | 33% |
| 5.3 Configure SSH Server | 10 | 10 | 0 | 0 | 0 | 10.0 | 20.0 | 50% |
| 5.4 Configure PAM | 1 | 3 | 0 | 0 | 0 | 1.0 | 4.0 | 25% |
| 5.5 User Accounts and Environment | 4 | 5 | 0 | 0 | 0 | 4.0 | 9.0 | 44% |
| 5.5.1 Set Shadow Password Suite Parameters | 2 | 3 | 0 | 0 | 0 | 2.0 | 5.0 | 40% |
| 6 System Maintenance | 25 | 3 | 0 | 0 | 2 | 25.0 | 28.0 | 89% |
| 6.1 System File Permissions | 10 | 1 | 0 | 0 | 2 | 10.0 | 11.0 | 91% |
| 6.2 User and Group Settings | 15 | 2 | 0 | 0 | 0 | 15.0 | 17.0 | 88% |
| Total | 96 | 88 | 0 | 0 | 21 | 96.0 | 184.0 | 52% |
Note: Actual scores are subject to rounding errors. The sum of these values may not result in the exact overall score.
This benchmark contains 4 profiles.The Level 1 - Server profile was used for this assessment.
| Title | Description |
|---|---|
| Level 1 - Server |
Items in this profile intend to:
This profile is intended for servers. Show Profile XML
|
| Level 2 - Server |
This profile extends the "Level 1 - Server" profile. Items in this profile exhibit one or more of the following characteristics:
This profile is intended for servers. Show Profile XML
|
| Level 1 - Workstation |
Items in this profile intend to:
This profile is intended for workstations. Show Profile XML
|
| Level 2 - Workstation |
This profile extends the "Level 1 - Workstation" profile. Items in this profile exhibit one or more of the following characteristics:
This profile is intended for workstations. Show Profile XML
|
Items in this section are advised for all systems, but may be difficult or require extensive preparation after the initial setup of the system.
Directories that are used for system-wide functions can be further protected by placing them on separate partitions. This provides protection for resource exhaustion and enables the use of mounting options that are applicable to the directory's intended use. Users' data can be stored on separate partitions and have stricter mount options. A user partition is a filesystem that has been established for use by the users and does not contain software for system operations.
The recommendations in this section are easier to perform during initial system installation. If the system is already installed, it is recommended that a full backup be performed before repartitioning the system.
Note: If you are repartitioning a system that has already been installed, make sure the data has been copied over to the new partition, unmount it and then remove the data from the directory that was in the old partition. Otherwise it will still consume space in the old partition that will be masked when the new filesystem is mounted. For example, if a system is in single-user mode with no filesystems mounted and the administrator adds a lot of data to the /tmp directory, this data will still consume space in / once the /tmp filesystem is mounted unless it is removed first.
A number of uncommon filesystem types are supported under Linux. Removing support for unneeded filesystem types reduces the local attack surface of the system. If a filesystem type is not needed it should be disabled. Native Linux file systems are designed to ensure that built-in security controls function as expected. Non-native filesystems can lead to unexpected consequences to both the security and functionality of the system and should be used with caution. Many filesystems are created for niche use cases and are not maintained and supported as the operating systems are updated and patched. Users of non-native filesystems should ensure that there is attention and ongoing support for them, especially in light of frequent operating system changes.
Standard network connectivity and Internet access to cloud storage may make the use of non-standard filesystem formats to directly attach heterogeneous devices much less attractive.
Note: This should not be considered a comprehensive list of filesystems. You may wish to consider additions to those listed here for your environment.
The cramfs filesystem type is a compressed read-only Linux filesystem embedded in small footprint systems. A cramfs image can be used without having to first decompress the image.
Removing support for unneeded filesystem types reduces the local attack surface of the server. If this filesystem type is not needed, disable it.
Edit or create a file in the /etc/modprobe.d/ directory ending in .conf
Example: vim /etc/modprobe.d/cramfs.conf
and add the following line:
install cramfs /bin/true
Run the following command to unload the cramfs module:
# rmmod cramfs
| AND |
|
References:
CIS Controls V7.0:
The freevxfs filesystem type is a free version of the Veritas type filesystem. This is the primary filesystem type for HP-UX operating systems.
Removing support for unneeded filesystem types reduces the local attack surface of the system. If this filesystem type is not needed, disable it.
Edit or create a file in the /etc/modprobe.d/ directory ending in .conf
Example: vi /etc/modprobe.d/freevxfs.conf
and add the following line:
install freevxfs /bin/true
Run the following command to unload the freevxfs module:
rmmod freevxfs
| AND |
|
References:
CIS Controls V7.0:
The jffs2 (journaling flash filesystem 2) filesystem type is a log-structured filesystem used in flash memory devices.
Removing support for unneeded filesystem types reduces the local attack surface of the system. If this filesystem type is not needed, disable it.
Edit or create a file in the /etc/modprobe.d/ directory ending in .conf
Example: vi /etc/modprobe.d/jffs2.conf
and add the following line:
install jffs2 /bin/true
Run the following command to unload the jffs2 module:
# rmmod jffs2
| AND |
|
References:
CIS Controls V7.0:
The hfs filesystem type is a hierarchical filesystem that allows you to mount Mac OS filesystems.
Removing support for unneeded filesystem types reduces the local attack surface of the system. If this filesystem type is not needed, disable it.
Edit or create a file in the /etc/modprobe.d/ directory ending in .conf
Example: vi /etc/modprobe.d/hfs.conf
and add the following line:
install hfs /bin/true
Run the following command to unload the hfs module:
# rmmod hfs
| AND |
|
References:
CIS Controls V7.0:
The hfsplus filesystem type is a hierarchical filesystem designed to replace hfs that allows you to mount Mac OS filesystems.
Removing support for unneeded filesystem types reduces the local attack surface of the system. If this filesystem type is not needed, disable it.
Edit or create a file in the /etc/modprobe.d/ directory ending in .conf
Example: vi /etc/modprobe.d/hfsplus.conf
and add the following line:
install hfsplus /bin/true
Run the following command to unload the hfsplus module:
# rmmod hfsplus
| AND |
|
References:
CIS Controls V7.0:
The udf filesystem type is the universal disk format used to implement ISO/IEC 13346 and ECMA-167 specifications. This is an open vendor filesystem type for data storage on a broad range of media. This filesystem type is necessary to support writing DVDs and newer optical disc formats.
Removing support for unneeded filesystem types reduces the local attack surface of the system. If this filesystem type is not needed, disable it.
Edit or create a file in the /etc/modprobe.d/ directory ending in .conf
Example: vi /etc/modprobe.d/udf.conf
and add the following line:
install udf /bin/true
Run the following command to unload the udf module:
# rmmod udf
| AND |
|
References:
CIS Controls V7.0:
The /tmp directory is a world-writable directory used for temporary storage by all users and some applications
Making /tmp its own file system allows an administrator to set the noexec option on the mount, making /tmp useless for an attacker to install executable code. It would also prevent an attacker from establishing a hardlink to a system setuid program and wait for it to be updated. Once the program was updated, the hardlink would be broken and the attacker would have his own copy of the program. If the program happened to have a security vulnerability, the attacker could continue to exploit the known flaw.
This can be accomplished by either mounting tmpfs to /tmp, or creating a separate partition for /tmp.
Configure /etc/fstab as appropriate.
Example:
tmpfs /tmp tmpfs defaults,rw,nosuid,nodev,noexec,relatime 0 0
OR Run the following commands to enable systemd /tmp mounting:
Run the following command to create the tmp.mount file is the correct location:
# cp -v /usr/share/systemd/tmp.mount /etc/systemd/system/
Edit /etc/systemd/system/tmp.mount to configure the /tmp mount:
[Mount]
What=tmpfs
Where=/tmp
Type=tmpfs
Options=mode=1777,strictatime,nosuid,nodev,noexec
Run the following command to reload the systemd daemon with the unpdated tmp.mount unit file:
# systemctl daemon-reload
Run the following command to enable and start tmp.mount
# systemctl --now enable tmp.mount
Impact:
Since the /tmp directory is intended to be world-writable, there is a risk of resource exhaustion if it is not bound to a separate partition.
Running out of /tmp space is a problem regardless of what kind of filesystem lies under it, but in a default installation a disk-based /tmp will essentially have the whole disk available, as it only creates a single / partition. On the other hand, a RAM-based /tmp as with tmpfs will almost certainly be much smaller, which can lead to applications filling up the filesystem much more easily.
/tmp utilizing tmpfs can be resized using the size={size} parameter on the Options line on the tmp.mount file
| AND |
|
References:
CIS Controls V7.0:
The nodev mount option specifies that the filesystem cannot contain special devices.
Since the /tmp filesystem is not intended to support devices, set this option to ensure that users cannot attempt to create block or character special devices in /tmp .
Edit the /etc/fstab file OR the /etc/systemd/system/local-fs.target.wants/tmp.mount file:
If /etc/fstab is used to mount /tmp :
Edit the /etc/fstab file and add nodev to the fourth field (mounting options) for the /tmp partition. See the fstab(5) manual page for more information.
Run the following command to remount /tmp :
# mount -o remount,nodev /tmp
OR If systemd is used to mount /tmp :
Edit /etc/systemd/system/local-fs.target.wants/tmp.mount to add nodev to the /tmp mount options:
[Mount]
Options=mode=1777,strictatime,noexec,nodev,nosuid
Run the following command to restart the systemd daemon:
# systemctl daemon-reload
Run the following command to restart tmp.mount
# systemctl restart tmp.mount
| AND |
|
References:
CIS Controls V7.0:
USB storage provides a means to transfer and store files insuring persistence and availability of the files independent of network connection status. Its popularity and utility has led to USB-based malware being a simple and common means for network infiltration and a first step to establishing a persistent threat within a networked environment.
Note: An alternative solution to disabling the usb-storage module may be found in USBGuard. Use of USBGuard and construction of USB device policies should be done in alignment with site policy.
Restricting USB access on the system will decrease the physical attack surface for a device and diminish the possible vectors to introduce malware.
Edit or create a file in the /etc/modprobe.d/ directory ending in .conf
Example: vi /etc/modprobe.d/usb_storage.conf and add the following line:
install usb-storage /bin/true
Run the following command to unload the usb-storage module:
rmmod usb-storage
| AND |
|
References:
CIS Controls V7.0:
Debian Family Linux distributions use apt to install and update software packages. Patch management procedures may vary widely between enterprises. Large enterprises may choose to install a local updates server that can be used in place of their distributions servers, whereas a single deployment of a system may prefer to get updates directly. Updates can be performed automatically or manually, depending on the site's policy for patch management. Many large enterprises prefer to test patches on a non-production system before rolling out to production.
For the purpose of this benchmark, the requirement is to ensure that a patch management system is configured and maintained. The specifics on patch update procedures are left to the organization.
AIDE is a file integrity checking tool, similar in nature to Tripwire. While it cannot prevent intrusions, it can detect unauthorized changes to configuration files by alerting when the files are changed. When setting up AIDE, decide internally what the site policy will be concerning integrity checking. Review the AIDE quick start guide and AIDE documentation before proceeding.
AIDE takes a snapshot of filesystem state including modification times, permissions, and file hashes which can then be used to compare against the current state of the filesystem to detect modifications to the system.
By monitoring the filesystem state compromised files can be detected to prevent or limit the exposure of accidental or malicious misconfigurations or modified binaries.
Install AIDE using the appropriate package manager or manual installation:
# apt install aide aide-common
Configure AIDE as appropriate for your environment. Consult the AIDE documentation for options.
Run the following commands to initialize AIDE:
# aideinit
# mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
| AND |
|
References:
CIS Controls V7.0:
Periodic checking of the filesystem integrity is needed to detect changes to the filesystem.
Periodic file checking allows the system administrator to determine on a regular basis if critical files have been changed in an unauthorized fashion.
If cron will be used to schedule and run aide check:
Run the following command:
# crontab -u root -e
Add the following line to the crontab:
0 5 * * * /usr/bin/aide.wrapper --config /etc/aide/aide.conf --check
OR If aidecheck.service and aidecheck.timer will be used to schedule and run aide check:
Create or edit the file /etc/systemd/system/aidecheck.service and add the following lines:
[Unit]
Description=Aide Check
[Service]
Type=simple
ExecStart=/usr/bin/aide.wrapper --config /etc/aide/aide.conf --check
[Install]
WantedBy=multi-user.target
Create or edit the file /etc/systemd/system/aidecheck.timer and add the following lines:
[Unit]
Description=Aide check every day at 5AM
[Timer]
OnCalendar=*-*-* 05:00:00
Unit=aidecheck.service
[Install]
WantedBy=multi-user.target
Run the following commands:
# chown root:root /etc/systemd/system/aidecheck.*
# chmod 0644 /etc/systemd/system/aidecheck.*
# systemctl daemon-reload
# systemctl enable aidecheck.service
# systemctl --now enable aidecheck.timer
| OR |
|
References:
CIS Controls V7.0:
The recommendations in this section focus on securing the bootloader and settings involved in the boot process directly.
The permissions on /boot/grub/grub.cfg are changed to 444 when grub.cfg is updated by the update-grub command
Setting the permissions to read and write for root only prevents non-root users from seeing the boot parameters or changing them. Non-root users who read the boot parameters may be able to identify weaknesses in security upon boot and be able to exploit them.
Run the following command to update chmod 444 to chmod 400 in /usr/sbin/grub-mkconfig :
# sed -ri 's/chmod\s+[0-7][0-7][0-7]\s+\$\{grub_cfg\}\.new/chmod 400 ${grub_cfg}.new/'
/usr/sbin/grub-mkconfig
Run the following command to remove check on password not being set to before running chmod command:
# sed -ri 's/ && ! grep "\^password" \$\{grub_cfg\}.new >\/dev\/null//' /usr/sbin/grub-mkconfig
| AND |
|
References:
CIS Controls V7.0:
Setting the boot loader password will require that anyone rebooting the system must enter a password before being able to set command line boot parameters
Requiring a boot password upon execution of the boot loader will prevent an unauthorized user from entering boot parameters or changing the boot partition. This prevents users from weakening security (e.g. turning off AppArmor at boot time).
Create an encrypted password with grub-mkpasswd-pbkdf2 :
# grub-mkpasswd-pbkdf2
Enter password: <password>
Reenter password: <password>
PBKDF2 hash of your password is <encrypted-password>
Add the following into a custom /etc/grub.d configuration file:
cat <<EOF
set superusers="<username>"
password_pbkdf2 <username> <encrypted-password>
EOF
The superuser/user information and password should not be contained in the /etc/grub.d/00_header file as this file could be overwritten in a package update.
If there is a requirement to be able to boot/reboot without entering the password, edit /etc/grub.d/10_linux and add --unrestricted to the line CLASS=
Example:
CLASS="--class gnu-linux --class gnu --class os --unrestricted"
Run the following command to update the grub2 configuration:
# update-grub
Impact:
If password protection is enabled, only the designated superuser can edit a Grub 2 menu item by pressing "e" or access the GRUB 2 command line by pressing "c"
If GRUB 2 is set up to boot automatically to a password-protected menu entry the user has no option to back out of the password prompt to select another menu entry. Holding the SHIFT key will not display the menu in this case. The user must enter the correct username and password. If unable, the configuration files will have to be edited via the LiveCD or other means to fix the problem
You can add --unrestricted to the menu entries to allow the system to boot without entering a password. Password will still be required to edit menu items.
More Information: https://help.ubuntu.com/community/Grub2/Passwords
| AND |
|
References:
CIS Controls V7.0:
The grub configuration file contains information on boot settings and passwords for unlocking boot options.
Setting the permissions to read and write for root only prevents non-root users from seeing the boot parameters or changing them. Non-root users who read the boot parameters may be able to identify weaknesses in security upon boot and be able to exploit them.
Run the following commands to set permissions on your grub configuration:
# chown root:root /boot/grub/grub.cfg
# chmod u-wx,go-rwx /boot/grub/grub.cfg
| AND |
|
References:
CIS Controls V7.0:
A core dump is the memory of an executable program. It is generally used to determine why a program aborted. It can also be used to glean confidential information from a core file. The system provides the ability to set a soft limit for core dumps, but this can be overridden by the user.
Setting a hard limit on core dumps prevents users from overriding the soft variable. If core dumps are required, consider setting limits for user groups (see limits.conf(5) ). In addition, setting the fs.suid_dumpable variable to 0 will prevent setuid programs from dumping core.
Add the following line to /etc/security/limits.conf or a /etc/security/limits.d/* file:
* hard core 0
Set the following parameter in /etc/sysctl.conf or a /etc/sysctl.d/* file:
fs.suid_dumpable = 0
Run the following command to set the active kernel parameter:
# sysctl -w fs.suid_dumpable=0
IF systemd-coredump is installed:
edit /etc/systemd/coredump.conf and add/modify the following lines:
Storage=none
ProcessSizeMax=0
Run the command:
systemctl daemon-reload
| AND |
|
References:
CIS Controls V7.0:
Mandatory Access Control (MAC) provides an additional layer of access restrictions to processes on top of the base Discretionary Access Controls. By restricting how processes can access files and resources on a system the potential impact from vulnerabilities in the processes can be reduced.
Impact: Mandatory Access Control limits the capabilities of applications and daemons on a system, while this can prevent unauthorized access the configuration of MAC can be complex and difficult to implement correctly preventing legitimate access from occurring.
Notes:
AppArmor provides a Mandatory Access Control (MAC) system that greatly augments the default Discretionary Access Control (DAC) model. Under AppArmor MAC rules are applied by file paths instead of by security contexts as in other MAC systems. As such it does not require support in the filesystem and can be applied to network mounted filesystems for example. AppArmor security policies define what system resources applications can access and what privileges they can do so with. This automatically limits the damage that the software can do to files accessible by the calling user. The user does not need to take any action to gain this benefit. For an action to occur, both the traditional DAC permissions must be satisfied as well as the AppArmor MAC rules. The action will not be allowed if either one of these models does not permit the action. In this way, AppArmor rules can only make a system's permissions more restrictive and secure.
References:
Configure AppArmor to be enabled at boot time and verify that it has not been overwritten by the bootloader boot parameters.
Note: This recommendation is designed around the grub bootloader, if LILO or another bootloader is in use in your environment enact equivalent settings.
AppArmor must be enabled at boot time in your bootloader configuration to ensure that the controls it provides are not overridden.
Edit /etc/default/grub and add the apparmor=1 and security=apparmor parameters to the GRUB_CMDLINE_LINUX= line
GRUB_CMDLINE_LINUX="apparmor=1 security=apparmor"
Run the following command to update the grub2 configuration:
# update-grub
| AND |
|
References:
CIS Controls V7.0:
AppArmor profiles define what resources applications are able to access.
Security configuration requirements vary from site to site. Some sites may mandate a policy that is stricter than the default policy, which is perfectly acceptable. This item is intended to ensure that any policies that exist on the system are activated.
Run the following command to set all profiles to enforce mode:
# aa-enforce /etc/apparmor.d/*
OR
Run the following command to set all profiles to complain mode:
# aa-complain /etc/apparmor.d/*
Note: Any unconfined processes may need to have a profile created or activated for them and then be restarted
| AND |
|
References:
CIS Controls V7.0:
Presenting a warning message prior to the normal user login may assist in the prosecution of trespassers on the computer system. Changing some of these login banners also has the side effect of hiding OS version information and other detailed system information from attackers attempting to target specific exploits at a system. The /etc/motd , /etc/issue , and /etc/issue.net files govern warning banners for standard command line logins for both local and remote users.
Guidelines published by the US Department of Defense require that warning messages include at least the name of the organization that owns the system, the fact that the system is subject to monitoring and that such monitoring is in compliance with local statutes, and that use of the system implies consent to such monitoring. It is important that the organization's legal counsel review the content of all messages before any system modifications are made, as these warning messages are inherently site-specific. More information (including citations of relevant case law) can be found at http://www.justice.gov/criminal/cybercrime/
Note: The text provided in the remediation actions for these items is intended as an example only. Please edit to include the specific text for your organization as approved by your legal department
The contents of the /etc/issue.net file are displayed to users prior to login for remote connections from configured services.
Unix-based systems have typically displayed information about the OS release and patch level upon logging in to the system. This information can be useful to developers who are developing software for a particular OS platform. If mingetty(8) supports the following options, they display operating system information: \m - machine architecture \r - operating system release \s - operating system name \v - operating system version
Warning messages inform users who are attempting to login to the system of their legal status regarding the system and must include the name of the organization that owns the system and any monitoring policies that are in place. Displaying OS and patch level information in login banners also has the side effect of providing detailed system information to attackers attempting to target specific exploits of a system. Authorized users can easily get this information by running the " uname -a " command once they have logged in.
Edit the /etc/issue.net file with the appropriate contents according to your site policy, remove any instances of \m , \r , \s , \v or references to the OS platform
# echo "Authorized uses only. All activity may be monitored and reported." > /etc/issue.net
| AND |
|
References:
CIS Controls V7.0:
The contents of the /etc/issue file are displayed to users prior to login for local terminals.
Unix-based systems have typically displayed information about the OS release and patch level upon logging in to the system. This information can be useful to developers who are developing software for a particular OS platform. If mingetty(8) supports the following options, they display operating system information: \m - machine architecture \r - operating system release \s - operating system name \v - operating system version - or the operating system's name
Warning messages inform users who are attempting to login to the system of their legal status regarding the system and must include the name of the organization that owns the system and any monitoring policies that are in place. Displaying OS and patch level information in login banners also has the side effect of providing detailed system information to attackers attempting to target specific exploits of a system. Authorized users can easily get this information by running the " uname -a " command once they have logged in.
Edit the /etc/issue file with the appropriate contents according to your site policy, remove any instances of \m , \r , \s , \v or references to the OS platform
# echo "Authorized uses only. All activity may be monitored and reported." > /etc/issue
| AND |
|
References:
CIS Controls V7.0:
The GNOME Display Manager (GDM) is a program that manages graphical display servers and handles graphical user logins.
Note: If GDM is not installed on the system, this section can be skipped
While applying system updates and patches helps correct known vulnerabilities, one of the best ways to protect the system against as yet unreported vulnerabilities is to disable all services that are not required for normal system operation. This prevents the exploitation of vulnerabilities discovered at a later date. If a service is not enabled, it cannot be exploited. The actions in this section of the document provide guidance on some services which can be safely disabled and under which circumstances, greatly reducing the number of possible threats to the resulting system. Additionally some services which should remain enabled but with secure configuration are covered as well as insecure service clients.
Note: This should not be considered a comprehensive list of insecure services. You may wish to consider additions to those listed here for your environment.
This section describes services that are installed on systems that specifically need to run these services. If any of these services are not required, it is recommended that they be deleted from the system to reduce the potential attack surface. If a package is required as a dependency, and the service is not required, the service should be stopped and masked.
The following command can be used to stop and mask the service:
# systemctl --now mask <service_name>
It is recommended that physical systems and virtual guests lacking direct access to the physical host's clock be configured to synchronize their time using a service such as systemd-timesyncd, chrony, or ntp.
Notes:
HTTP or web servers provide the ability to host web site content.
Unless there is a need to run the system as a web server, it is recommended that the package be deleted to reduce the potential attack surface.
Run the following command to remove apache :
# apt purge apache2
| AND |
|
References:
CIS Controls V7.0:
A number of insecure services exist. While disabling the servers prevents a local attack against these services, it is advised to remove their clients unless they are required.
Note: This should not be considered a comprehensive list of insecure service clients. You may wish to consider additions to those listed here for your environment.
The telnet package contains the telnet client, which allows users to start connections to other systems via the telnet protocol.
The telnet protocol is insecure and unencrypted. The use of an unencrypted transmission medium could allow an unauthorized user to steal credentials. The ssh package provides an encrypted session and stronger security and is included in most Linux distributions.
Uninstall telnet :
# apt purge telnet
Impact:
Many insecure service clients are used as troubleshooting tools and in testing environments. Uninstalling them can inhibit capability to test and troubleshoot. If they are required it is advisable to remove the clients after use to prevent accidental or intentional misuse.
| AND |
|
References:
CIS Controls V7.0:
This section provides guidance on for securing the network configuration of the system through kernel parameters, access list control, and firewall settings.
To reduce the attack surface of a system, unused network protocols and devices should be disabled.
The following network parameters are intended for use if the system is to act as a host only. A system is considered host only if the system has a single interface, or has multiple interfaces but will not be configured as a router.
Note:
Configuration files are read from directories in /etc/ , /run/ , /usr/local/lib/ , and /lib/ , in order of precedence. Files must have the the ".conf" extension. extension. Files in /etc/ override files with the same name in /run/ , /usr/local/lib/ , and /lib/ . Files in /run/ override files with the same name under /usr/ .
All configuration files are sorted by their filename in lexicographic order, regardless of which of the directories they reside in. If multiple files specify the same option, the entry in the file with the lexicographically latest name will take precedence. Thus, the configuration in a certain file may either be replaced completely (by placing a file with the same name in a directory with higher priority), or individual settings might be changed (by specifying additional settings in a file with a different name that is ordered later).
Packages should install their configuration files in /usr/lib/ (distribution packages) or /usr/local/lib/ (local installs). Files in /etc/ are reserved for the local administrator, who may use this logic to override the configuration files installed by vendor packages. It is recommended to prefix all filenames with a two-digit number and a dash, to simplify the ordering of the files.
If the administrator wants to disable a configuration file supplied by the vendor, the recommended way is to place a symlink to /dev/null in the configuration directory in /etc/ , with the same filename as the vendor configuration file. If the vendor configuration file is included in the initrd image, the image has to be regenerated.
ICMP Redirects are used to send routing information to other hosts. As a host itself does not act as a router (in a host only configuration), there is no need to send redirects.
An attacker could use a compromised host to send invalid ICMP redirects to other router devices in an attempt to corrupt routing and have users access a system set up by the attacker as opposed to a valid system.
Set the following parameters in /etc/sysctl.conf or a /etc/sysctl.d/* file:
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
Run the following commands to set the active kernel parameters:
# sysctl -w net.ipv4.conf.all.send_redirects=0
# sysctl -w net.ipv4.conf.default.send_redirects=0
# sysctl -w net.ipv4.route.flush=1
| AND |
|
References:
CIS Controls V7.0:
The net.ipv4.ip_forward and net.ipv6.conf.all.forwarding flags are used to tell the system whether it can forward packets or not.
Setting the flags to 0 ensures that a system with multiple interfaces (for example, a hard proxy), will never be able to forward packets, and therefore, never serve as a router.
Run the following command to restore the default parameter and set the active kernel parameter:
# grep -Els "^\s*net\.ipv4\.ip_forward\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf
/usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | while read filename; do sed -ri "s/^\s*(net\.ipv4\.ip_forward\s*)(=)(\s*\S+\b).*$/#
*REMOVED* \1/" $filename; done; sysctl -w net.ipv4.ip_forward=0; sysctl -w net.ipv4.route.flush=1
IF IPv6 is enabled:
Run the following command to restore the default parameter and set the active kernel parameter:
# grep -Els "^\s*net\.ipv6\.conf\.all\.forwarding\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf
/usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | while read filename; do sed -ri "s/^\s*(net\.ipv6\.conf\.all\.forwarding\s*)(=)(\s*\S+\b).*$/#
*REMOVED* \1/" $filename; done; sysctl -w net.ipv6.conf.all.forwarding=0; sysctl -w
net.ipv6.route.flush=1
| AND |
|
References:
CIS Controls V7.0:
The following network parameters are intended for use on both host only and router systems. A system acts as a router if it has at least two interfaces and is configured to perform routing functions.
Note:
Configuration files are read from directories in /etc/ , /run/ , /usr/local/lib/ , and /lib/ , in order of precedence. Files must have the the ".conf" extension. extension. Files in /etc/ override files with the same name in /run/ , /usr/local/lib/ , and /lib/ . Files in /run/ override files with the same name under /usr/ .
All configuration files are sorted by their filename in lexicographic order, regardless of which of the directories they reside in. If multiple files specify the same option, the entry in the file with the lexicographically latest name will take precedence. Thus, the configuration in a certain file may either be replaced completely (by placing a file with the same name in a directory with higher priority), or individual settings might be changed (by specifying additional settings in a file with a different name that is ordered later).
Packages should install their configuration files in /usr/lib/ (distribution packages) or /usr/local/lib/ (local installs). Files in /etc/ are reserved for the local administrator, who may use this logic to override the configuration files installed by vendor packages. It is recommended to prefix all filenames with a two-digit number and a dash, to simplify the ordering of the files.
If the administrator wants to disable a configuration file supplied by the vendor, the recommended way is to place a symlink to /dev/null in the configuration directory in /etc/ , with the same filename as the vendor configuration file. If the vendor configuration file is included in the initrd image, the image has to be regenerated.
In networking, source routing allows a sender to partially or fully specify the route packets take through a network. In contrast, non-source routed packets travel a path determined by routers in the network. In some cases, systems may not be routable or reachable from some locations (e.g. private addresses vs. Internet routable), and so source routed packets would need to be used.
Setting net.ipv4.conf.all.accept_source_route, net.ipv4.conf.default.accept_source_route, net.ipv6.conf.all.accept_source_route and net.ipv6.conf.default.accept_source_route to 0 disables the system from accepting source routed packets. Assume this system was capable of routing packets to Internet routable addresses on one interface and private addresses on another interface. Assume that the private addresses were not routable to the Internet routable addresses and vice versa. Under normal routing circumstances, an attacker from the Internet routable addresses could not use the system as a way to reach the private address systems. If, however, source routed packets were allowed, they could be used to gain access to the private address systems as the route could be specified, rather than rely on routing protocols that did not allow this routing.
Set the following parameters in /etc/sysctl.conf or a /etc/sysctl.d/* file:
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
Run the following commands to set the active kernel parameters:
# sysctl -w net.ipv4.conf.all.accept_source_route=0
# sysctl -w net.ipv4.conf.default.accept_source_route=0
# sysctl -w net.ipv4.route.flush=1
IF IPv6 is enabled:
Set the following parameters in /etc/sysctl.conf or a /etc/sysctl.d/* file:
net.ipv6.conf.all.accept_source_route = 0
net.ipv6.conf.default.accept_source_route = 0
Run the following commands to set the active kernel parameters:
# sysctl -w net.ipv6.conf.all.accept_source_route=0
# sysctl -w net.ipv6.conf.default.accept_source_route=0
# sysctl -w net.ipv6.route.flush=1
| AND |
|
References:
CIS Controls V7.0:
ICMP redirect messages are packets that convey routing information and tell your host (acting as a router) to send packets via an alternate path. It is a way of allowing an outside routing device to update your system routing tables. By setting net.ipv4.conf.all.accept_redirects and net.ipv6.conf.all.accept_redirects to 0, the system will not accept any ICMP redirect messages, and therefore, won't allow outsiders to update the system's routing tables.
Attackers could use bogus ICMP redirect messages to maliciously alter the system routing tables and get them to send packets to incorrect networks and allow your system packets to be captured.
Set the following parameters in /etc/sysctl.conf or a /etc/sysctl.d/* file:
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
Run the following commands to set the active kernel parameters:
# sysctl -w net.ipv4.conf.all.accept_redirects=0
# sysctl -w net.ipv4.conf.default.accept_redirects=0
# sysctl -w net.ipv4.route.flush=1
IF IPv6 is enabled:
Set the following parameters in /etc/sysctl.conf or a /etc/sysctl.d/* file:
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
Run the following commands to set the active kernel parameters:
# sysctl -w net.ipv6.conf.all.accept_redirects=0
# sysctl -w net.ipv6.conf.default.accept_redirects=0
# sysctl -w net.ipv6.route.flush=1
| AND |
|
References:
CIS Controls V7.0:
Secure ICMP redirects are the same as ICMP redirects, except they come from gateways listed on the default gateway list. It is assumed that these gateways are known to your system, and that they are likely to be secure.
It is still possible for even known gateways to be compromised. Setting net.ipv4.conf.all.secure_redirects to 0 protects the system from routing table updates by possibly compromised known gateways.
Set the following parameters in /etc/sysctl.conf or a /etc/sysctl.d/* file:
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
Run the following commands to set the active kernel parameters:
# sysctl -w net.ipv4.conf.all.secure_redirects=0
# sysctl -w net.ipv4.conf.default.secure_redirects=0
# sysctl -w net.ipv4.route.flush=1
| AND |
|
References:
CIS Controls V7.0:
When enabled, this feature logs packets with un-routable source addresses to the kernel log.
Enabling this feature and logging these packets allows an administrator to investigate the possibility that an attacker is sending spoofed packets to their system.
Set the following parameters in /etc/sysctl.conf or a /etc/sysctl.d/* file:
net.ipv4.conf.all.log_martians = 1
net.ipv4.conf.default.log_martians = 1
Run the following commands to set the active kernel parameters:
# sysctl -w net.ipv4.conf.all.log_martians=1
# sysctl -w net.ipv4.conf.default.log_martians=1
# sysctl -w net.ipv4.route.flush=1
| AND |
|
References:
CIS Controls V7.0:
Setting net.ipv4.icmp_echo_ignore_broadcasts to 1 will cause the system to ignore all ICMP echo and timestamp requests to broadcast and multicast addresses.
Accepting ICMP echo and timestamp requests with broadcast or multicast destinations for your network could be used to trick your host into starting (or participating) in a Smurf attack. A Smurf attack relies on an attacker sending large amounts of ICMP broadcast messages with a spoofed source address. All hosts receiving this message and responding would send echo-reply messages back to the spoofed address, which is probably not routable. If many hosts respond to the packets, the amount of traffic on the network could be significantly multiplied.
Set the following parameters in /etc/sysctl.conf or a /etc/sysctl.d/* file:
net.ipv4.icmp_echo_ignore_broadcasts = 1
Run the following commands to set the active kernel parameters:
# sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1
# sysctl -w net.ipv4.route.flush=1
| AND |
|
References:
CIS Controls V7.0:
Setting icmp_ignore_bogus_error_responses to 1 prevents the kernel from logging bogus responses (RFC-1122 non-compliant) from broadcast reframes, keeping file systems from filling up with useless log messages.
Some routers (and some attackers) will send responses that violate RFC-1122 and attempt to fill up a log file system with many useless error messages.
Set the following parameter in /etc/sysctl.conf or a /etc/sysctl.d/* file:
net.ipv4.icmp_ignore_bogus_error_responses = 1
Run the following commands to set the active kernel parameters:
# sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1
# sysctl -w net.ipv4.route.flush=1
| AND |
|
References:
CIS Controls V7.0:
Setting net.ipv4.conf.all.rp_filter and net.ipv4.conf.default.rp_filter to 1 forces the Linux kernel to utilize reverse path filtering on a received packet to determine if the packet was valid. Essentially, with reverse path filtering, if the return packet does not go out the same interface that the corresponding source packet came from, the packet is dropped (and logged if log_martians is set).
Setting these flags is a good way to deter attackers from sending your system bogus packets that cannot be responded to. One instance where this feature breaks down is if asymmetrical routing is employed. This would occur when using dynamic routing protocols (bgp, ospf, etc) on your system. If you are using asymmetrical routing on your system, you will not be able to enable this feature without breaking the routing.
Set the following parameters in /etc/sysctl.conf or a /etc/sysctl.d/* file:
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
Run the following commands to set the active kernel parameters:
# sysctl -w net.ipv4.conf.all.rp_filter=1
# sysctl -w net.ipv4.conf.default.rp_filter=1
# sysctl -w net.ipv4.route.flush=1
| AND |
|
References:
CIS Controls V7.0:
This setting disables the system's ability to accept IPv6 router advertisements.
It is recommended that systems do not accept router advertisements as they could be tricked into routing traffic to compromised machines. Setting hard routes within the system (usually a single default route to a trusted router) protects the system from bad routes.
IF IPv6 is enabled:
Set the following parameters in /etc/sysctl.conf or a /etc/sysctl.d/* file:
net.ipv6.conf.all.accept_ra = 0
net.ipv6.conf.default.accept_ra = 0
Run the following commands to set the active kernel parameters:
# sysctl -w net.ipv6.conf.all.accept_ra=0
# sysctl -w net.ipv6.conf.default.accept_ra=0
# sysctl -w net.ipv6.route.flush=1
| OR |
|
References:
CIS Controls V7.0:
The Linux kernel modules support several network protocols that are not commonly used. If these protocols are not needed, it is recommended that they be disabled in the kernel.
Note: This should not be considered a comprehensive list of uncommon network protocols, you may wish to consider additions to those listed here for your environment.
A firewall is a set of rules. When a data packet moves into or out of a protected network space, its contents (in particular, information about its origin, target, and the protocol it plans to use) are tested against the firewall rules to see if it should be allowed through
To provide a Host Based Firewall, the Linux kernel includes support for:
In order to configure firewall rules for Netfilter or nftables, a firewall utility needs to be installed. Guidance has been included for the following firewall utilities:
Notes:
If nftables or iptables are being used in your environment, please follow the guidance in their respective section and pass-over the guidance in this section.
Uncomplicated Firewall (UFW) is a program for managing a netfilter firewall designed to be easy to use.
Notes:
The Uncomplicated Firewall (ufw) is a frontend for iptables and is particularly well-suited for host-based firewalls. ufw provides a framework for managing netfilter, as well as a command-line interface for manipulating the firewall
A firewall utility is required to configure the Linux kernel's netfilter framework via the iptables or nftables back-end.
The Linux kernel's netfilter framework host-based firewall can protect against threats originating from within a corporate network to include malicious mobile code and poorly configured software on a host.
Note: Only one firewall utility should be installed and configured. UFW is dependent on the iptables package
Run the following command to install Uncomplicated Firewall (UFW):
apt install ufw
| OR |
|
References:
CIS Controls V7.0:
UncomplicatedFirewall (ufw) is a frontend for iptables. ufw provides a framework for managing netfilter, as well as a command-line and available graphical user interface for manipulating the firewall.
Notes:
# ufw allow proto tcp from any to any port 22
The ufw service must be enabled and running in order for ufw to protect the system
Run the following command to enable ufw:
# ufw enable
Impact:
Changing firewall settings while connected over network can result in being locked out of the system.
| OR |
|
References:
CIS Controls V7.0:
Configure the loopback interface to accept traffic. Configure all other interfaces to deny traffic to the loopback network (127.0.0.0/8 for IPv4 and ::1/128 for IPv6).
Loopback traffic is generated between processes on machine and is typically critical to operation of the system. The loopback interface is the only place that loopback network (127.0.0.0/8 for IPv4 and ::1/128 for IPv6) traffic should be seen, all other interfaces should ignore traffic on this network as an anti-spoofing measure.
Run the following commands to implement the loopback rules:
# ufw allow in on lo
# ufw allow out on lo
# ufw deny in from 127.0.0.0/8
# ufw deny in from ::1
| OR |
|
References:
CIS Controls V7.0:
A default deny policy on connections ensures that any unconfigured network usage will be rejected.
Note: Any port or protocol without a explicit allow before the default deny will be blocked
With a default accept policy the firewall will accept any packet that is not configured to be denied. It is easier to white list acceptable usage than to black list unacceptable usage.
Run the following commands to implement a default deny policy:
# ufw default deny incoming
# ufw default deny outgoing
# ufw default deny routed
Impact:
Any port and protocol not explicitly allowed will be blocked. The following rules should be considered before applying the default deny.
ufw allow git
ufw allow in http
ufw allow in https
ufw allow out 53
ufw logging on
| OR |
|
References:
CIS Controls V7.0:
If Uncomplicated Firewall (UFW) or iptables are being used in your environment, please follow the guidance in their respective section and pass-over the guidance in this section.
nftables is a subsystem of the Linux kernel providing filtering and classification of network packets/datagrams/frames and is the successor to iptables. The biggest change with the successor nftables is its simplicity. With iptables, we have to configure every single rule and use the syntax which can be compared with normal commands. With nftables, the simpler syntax, much like BPF (Berkely Packet Filter) means shorter lines and less repetition. Support for nftables should also be compiled into the kernel, together with the related nftables modules. Please ensure that your kernel supports nf_tables before choosing this option.
Notes:
The following will implement the firewall rules of this section and open ICMP, IGMP, and port 22(ssh) from anywhere. Opening the ports for ICMP, IGMP, and port 22(ssh) needs to be updated in accordance with local site policy. Allow port 22(ssh) needs to be updated to only allow systems requiring ssh connectivity to connect, as per site policy.
Save the script bellow as /etc/nftables.rules
#!/sbin/nft -f
# This nftables.rules config should be saved as /etc/nftables.rules
# flush nftables rulesset
flush ruleset
# Load nftables ruleset
# nftables config with inet table named filter
table inet filter {
# Base chain for input hook named input (Filters inbound network packets)
chain input {
type filter hook input priority 0; policy drop;
# Ensure loopback traffic is configured
iif "lo" accept
ip saddr 127.0.0.0/8 counter packets 0 bytes 0 drop
ip6 saddr ::1 counter packets 0 bytes 0 drop
# Ensure established connections are configured
ip protocol tcp ct state established accept
ip protocol udp ct state established accept
ip protocol icmp ct state established accept
# Accept port 22(SSH) traffic from anywhere
tcp dport ssh accept
# Accept ICMP and IGMP from anywhere
icmpv6 type { destination-unreachable, packet-too-big, time-exceeded, parameter-problem,
mld-listener-query, mld-listener-report, mld-listener-done, nd-router-solicit, nd-router-advert,
nd-neighbor-solicit, nd-neighbor-advert, ind-neighbor-solicit, ind-neighbor-advert,
mld2-listener-report } accept
icmp type { destination-unreachable, router-advertisement, router-solicitation, time-exceeded,
parameter-problem } accept
ip protocol igmp accept
}
# Base chain for hook forward named forward (Filters forwarded network packets)
chain forward {
type filter hook forward priority 0; policy drop;
}
# Base chain for hook output named output (Filters outbount network packets)
chain output {
type filter hook output priority 0; policy drop;
# Ensure outbound and established connections are configured
ip protocol tcp ct state established,related,new accept
ip protocol udp ct state established,related,new accept
ip protocol icmp ct state established,related,new accept
}
}
Run the following command to load the file into nftables
# nft -f /etc/nftables.rules
All changes in the nftables subsections are temporary.
To make these changes permanent:
Run the following command to create the nftables.rules file
nft list ruleset > /etc/nftables.rules
Add the following line to /etc/nftables.conf
include "/etc/nftables.rules"
nftables provides a new in-kernel packet classification framework that is based on a network-specific Virtual Machine (VM) and a new nft userspace command line tool. nftables reuses the existing Netfilter subsystems such as the existing hook infrastructure, the connection tracking system, NAT, userspace queuing and logging subsystem.
Notes:
nftables is a subsystem of the Linux kernel that can protect against threats originating from within a corporate network to include malicious mobile code and poorly configured software on a host.
Run the following command to install nftables :
# apt install nftables
| OR |
|
References:
CIS Controls V7.0:
Tables hold chains. Each table only has one address family and only applies to packets of this family. Tables can have one of five families.
nftables doesn't have any default tables. Without a table being build, nftables will not filter network traffic.
Run the following command to create a table in nftables
# nft create table inet <table name>
Example:
# nft create table inet filter
Impact:
Adding rules to a running nftables can cause loss of connectivity to the system
| OR |
|
References:
CIS Controls V7.0:
Chains are containers for rules. They exist in two kinds, base chains and regular chains. A base chain is an entry point for packets from the networking stack, a regular chain may be used as jump target and is used for better rule organization.
If a base chain doesn't exist with a hook for input, forward, and delete, packets that would flow through those chains will not be touched by nftables.
Run the following command to create the base chains:
# nft create chain inet <table name> <base chain name> { type filter hook <(input|forward|output)>
priority 0 \; }
Example:
# nft create chain inet filter input { type filter hook input priority 0 \; }
# nft create chain inet filter forward { type filter hook forward priority 0 \; }
# nft create chain inet filter output { type filter hook output priority 0 \; }
Impact:
If configuring nftables over ssh, creating a base chain with a policy of drop will cause loss of connectivity.
Ensure that a rule allowing ssh has been added to the base chain prior to setting the base chain's policy to drop
| OR |
|
References:
CIS Controls V7.0:
Configure the loopback interface to accept traffic. Configure all other interfaces to deny traffic to the loopback network
Loopback traffic is generated between processes on machine and is typically critical to operation of the system. The loopback interface is the only place that loopback network traffic should be seen, all other interfaces should ignore traffic on this network as an anti-spoofing measure.
Run the following commands to implement the loopback rules:
# nft add rule inet filter input iif lo accept
# nft create rule inet filter input ip saddr 127.0.0.0/8 counter drop
IF IPv6 is enabled on the system:
Run the following command to implement the IPv6 loopback rule:
# nft add rule inet filter input ip6 saddr ::1 counter drop
| OR |
|
References:
CIS Controls V7.0:
Base chain policy is the default verdict that will be applied to packets reaching the end of the chain.
There are two policies: accept (Default) and drop. If the policy is set to accept , the firewall will accept any packet that is not configured to be denied and the packet will continue transversing the network stack.
It is easier to white list acceptable usage than to black list unacceptable usage.
Note: Changing firewall settings while connected over network can result in being locked out of the system.
Run the following command for the base chains with the input, forward, and output hooks to implement a default DROP policy:
# nft chain <table family> <table name> <chain name> { policy drop \; }
Example:
# nft chain inet filter input { policy drop \; }
# nft chain inet filter forward { policy drop \; }
# nft chain inet filter output { policy drop \; }
Impact:
If configuring nftables over ssh, creating a base chain with a policy of drop will cause loss of connectivity.
Ensure that a rule allowing ssh has been added to the base chain prior to setting the base chain's policy to drop
| OR |
|
References:
CIS Controls V7.0:
The nftables service allows for the loading of nftables rulesets during boot, or starting on the nftables service
The nftables service restores the nftables rules from the rules files referenced in the /etc/nftables.conf file during boot or the starting of the nftables service
Run the following command to enable the nftables service:
# systemctl enable nftables
| OR |
|
References:
CIS Controls V7.0:
nftables is a subsystem of the Linux kernel providing filtering and classification of network packets/datagrams/frames.
The nftables service reads the /etc/nftables.conf file for a nftables file or files to include in the nftables ruleset.
A nftables ruleset containing the input, forward, and output base chains allow network traffic to be filtered.
Changes made to nftables ruleset only affect the live system, you will also need to configure the nftables ruleset to apply on boot
Edit the /etc/nftables.conf file and un-comment or add a line with include <Absolute path to nftables rules file> for each nftables file you want included in the nftables ruleset on boot
Example:
# vi /etc/nftables.conf
Add the line:
include "/etc/nftables.rules"
| OR |
|
References:
CIS Controls V7.0:
If Uncomplicated Firewall (UFW) or nftables are being used in your environment, please follow the guidance in their respective section and pass-over the guidance in this section.
IPtables is an application that allows a system administrator to configure the IPv4 and IPv6 tables, chains and rules provided by the Linux kernel firewall. While several methods of configuration exist this section is intended only to ensure the resulting IPtables rules are in place, not how they are configured. If IPv6 is in use in your environment, similar settings should be applied to the IP6tables as well.
Note: Configuration of a live system's firewall directly over a remote connection will often result in being locked out
This section provides guidance for installing, enabling, removing, and disabling software packages necessary for using IPTables as the method for configuring and maintaining a Host Based Firewall on the system.
Note: Using more than one method to configure and maintain a Host Based Firewall can cause unexpected results. If FirewallD or NFTables are being used for configuration and maintenance, this section should be skipped and the guidance in their respective section followed.
iptables is a utility program that allows a system administrator to configure the tables provided by the Linux kernel firewall, implemented as different Netfilter modules, and the chains and rules it stores. Different kernel modules and programs are used for different protocols; iptables applies to IPv4, ip6tables to IPv6, arptables to ARP, and ebtables to Ethernet frames.
A method of configuring and maintaining firewall rules is necessary to configure a Host Based Firewall.
Run the following command to install iptables and iptables-persistent
# apt install iptables iptables-persistent
| OR |
|
References:
CIS Controls V7.0:
Iptables is used to set up, maintain, and inspect the tables of IP packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains and may also contain user-defined chains.
Each chain is a list of rules which can match a set of packets. Each rule specifies what to do with a packet that matches. This is called a 'target', which may be a jump to a user-defined chain in the same table.
Note: This section broadly assumes starting with an empty IPtables firewall ruleset (established by flushing the rules with iptables -F). Remediation steps included only affect the live system, you will also need to configure your default firewall configuration to apply on boot. Configuration of a live systems firewall directly over a remote connection will often result in being locked out. It is advised to have a known good firewall configuration set to run on boot and to configure an entire firewall structure in a script that is then run and tested before saving to boot. The following script will implement the firewall rules of this section and open port 22(ssh) from anywhere:
#!/bin/bash
# Flush IPtables rules
iptables -F
# Ensure default deny firewall policy
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
# Ensure loopback traffic is configured
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -s 127.0.0.0/8 -j DROP
# Ensure outbound and established connections are configured
iptables -A OUTPUT -p tcp -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p udp -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p icmp -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -p udp -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -p icmp -m state --state ESTABLISHED -j ACCEPT
# Open inbound ssh(tcp port 22) connections
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT
A default deny all policy on connections ensures that any unconfigured network usage will be rejected.
Notes:
With a default accept policy the firewall will accept any packet that is not configured to be denied. It is easier to white list acceptable usage than to black list unacceptable usage.
Run the following commands to implement a default DROP policy:
# iptables -P INPUT DROP
# iptables -P OUTPUT DROP
# iptables -P FORWARD DROP
| OR |
|
References:
CIS Controls V7.0:
Configure the loopback interface to accept traffic. Configure all other interfaces to deny traffic to the loopback network (127.0.0.0/8).
Notes:
Loopback traffic is generated between processes on machine and is typically critical to operation of the system. The loopback interface is the only place that loopback network (127.0.0.0/8) traffic should be seen, all other interfaces should ignore traffic on this network as an anti-spoofing measure.
Run the following commands to implement the loopback rules:
# iptables -A INPUT -i lo -j ACCEPT
# iptables -A OUTPUT -o lo -j ACCEPT
# iptables -A INPUT -s 127.0.0.0/8 -j DROP
| OR |
|
References:
CIS Controls V7.0:
Any ports that have been opened on non-loopback addresses need firewall rules to govern traffic.
Note:
Without a firewall rule configured for open ports default firewall policy will drop all packets to these ports.
For each port identified in the audit which does not have a firewall rule establish a proper rule for accepting inbound connections:
# iptables -A INPUT -p <protocol> --dport <port> -m state --state NEW -j ACCEPT
| OR |
|
References:
CIS Controls V7.0:
Ip6tables is used to set up, maintain, and inspect the tables of IPv6 packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains and may also contain user-defined chains. Each chain is a list of rules which can match a set of packets. Each rule specifies what to do with a packet that matches. This is called a `target', which may be a jump to a user-defined chain in the same table.
If IPv6 in enabled on the system, the ip6tables should be configured.
Note: This section broadly assumes starting with an empty ip6tables firewall ruleset (established by flushing the rules with ip6tables -F). Remediation steps included only affect the live system, you will also need to configure your default firewall configuration to apply on boot. Configuration of a live systems firewall directly over a remote connection will often result in being locked out. It is advised to have a known good firewall configuration set to run on boot and to configure an entire firewall structure in a script that is then run and tested before saving to boot.
The following script will implement the firewall rules of this section and open port 22(ssh) from anywhere:
#!/bin/bash
# Flush ip6tables rules
ip6tables -F
# Ensure default deny firewall policy
ip6tables -P INPUT DROP
ip6tables -P OUTPUT DROP
ip6tables -P FORWARD DROP
# Ensure loopback traffic is configured
ip6tables -A INPUT -i lo -j ACCEPT
ip6tables -A OUTPUT -o lo -j ACCEPT
ip6tables -A INPUT -s ::1 -j DROP
# Ensure outbound and established connections are configured
ip6tables -A OUTPUT -p tcp -m state --state NEW,ESTABLISHED -j ACCEPT
ip6tables -A OUTPUT -p udp -m state --state NEW,ESTABLISHED -j ACCEPT
ip6tables -A OUTPUT -p icmp -m state --state NEW,ESTABLISHED -j ACCEPT
ip6tables -A INPUT -p tcp -m state --state ESTABLISHED -j ACCEPT
ip6tables -A INPUT -p udp -m state --state ESTABLISHED -j ACCEPT
ip6tables -A INPUT -p icmp -m state --state ESTABLISHED -j ACCEPT
# Open inbound ssh(tcp port 22) connections
ip6tables -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT
A default deny all policy on connections ensures that any unconfigured network usage will be rejected.
Note:
With a default accept policy the firewall will accept any packet that is not configured to be denied. It is easier to white list acceptable usage than to black list unacceptable usage.
Run the following commands to implement a default DROP policy:
# ip6tables -P INPUT DROP
# ip6tables -P OUTPUT DROP
# ip6tables -P FORWARD DROP
| OR |
|
References:
CIS Controls V7.0:
Any ports that have been opened on non-loopback addresses need firewall rules to govern traffic.
Note:
Without a firewall rule configured for open ports default firewall policy will drop all packets to these ports.
For each port identified in the audit which does not have a firewall rule establish a proper rule for accepting inbound connections:
# ip6tables -A INPUT -p <protocol> --dport <port> -m state --state NEW -j ACCEPT
| OR |
|
References:
CIS Controls V7.0:
The items in this section describe how to configure logging, log monitoring, and auditing, using tools included in most distributions.
It is recommended that rsyslog be used for logging (with logwatch providing summarization) and auditd be used for auditing (with aureport providing summarization) to automatically monitor logs for intrusion attempts and other suspicious system behavior.
In addition to the local log files created by the steps in this section, it is also recommended that sites collect copies of their system logs on a secure, centralized log server via an encrypted connection. Not only does centralized logging help sites correlate events that may be occurring on multiple systems, but having a second copy of the system log information may be critical after a system compromise where the attacker has modified the local log files on the affected system(s). If a log correlation system is deployed, configure it to process the logs described in this section.
Because it is often necessary to correlate log information from many different systems (particularly after a security incident) it is recommended that the time be synchronized among systems and devices connected to the local network.
It is important that all logs described in this section be monitored on a regular basis and correlated to determine trends. A seemingly innocuous entry in one log could be more significant when compared to an entry in another log.
Note on log file permissions: There really isn't a "one size fits all" solution to the permissions on log files. Many sites utilize group permissions so that administrators who are in a defined security group, such as "wheel" do not have to elevate privileges to root in order to read log files. Also, if a third party log aggregation tool is used, it may need to have group permissions to read the log files, which is preferable to having it run setuid to root. Therefore, there are two remediation and audit steps for log file permissions. One is for systems that do not have a secured group method implemented that only permits root to read the log files ( root:root 600 ). The other is for sites that do have such a setup and are designated as root:securegrp 640 where securegrp is the defined security group (in some cases wheel ).
System auditing, through auditd , allows system administrators to monitor their systems such that they can detect unauthorized access or modification of data. By default, auditd will audit AppArmor AVC denials, system logins, account modifications, and authentication events. Events will be logged to /var/log/audit/audit.log . The recording of these events will use a modest amount of disk space on a system. If significantly more events are captured, additional on system or off system storage may need to be allocated.
Notes:
The capturing of system events provides system administrators with information to allow them to determine if unauthorized access to their system is occurring.
When auditing, it is important to carefully configure the storage requirements for audit logs. By default, auditd will max out the log files at 5MB and retain only 4 copies of them. Older versions will be deleted. It is possible on a system that the 20 MBs of audit logs may fill up the system causing loss of audit data. While the recommendations here provide guidance, check your site policy for audit storage requirements.
Logging services should be configured to prevent information leaks and to aggregate logs on a remote server so that they can be reviewed in the event of a system compromise and ease log analysis.
The rsyslog software is recommended as a replacement for the syslogd daemon and provides improvements over syslogd , such as connection-oriented (i.e. TCP) transmission of logs, the option to log to database formats, and the encryption of log data en route to a central logging server.
Note: This section only applies if rsyslog is installed on the system.
The rsyslog software is a recommended replacement to the original syslogd daemon which provide improvements over syslogd , such as connection-oriented (i.e. TCP) transmission of logs, the option to log to database formats, and the encryption of log data en route to a central logging server.
The security enhancements of rsyslog such as connection-oriented (i.e. TCP) transmission of logs, the option to log to database formats, and the encryption of log data en route to a central logging server) justify installing and configuring the package.
Install rsyslog:
# apt install rsyslog
| AND |
|
References:
CIS Controls V7.0:
Once the rsyslog package is installed it needs to be activated.
If the rsyslog service is not activated the system may default to the syslogd service or lack logging instead.
Run the following commands to enable rsyslog :
# systemctl --now enable rsyslog
| AND |
|
References:
CIS Controls V7.0:
rsyslog will create logfiles that do not already exist on the system. This setting controls what permissions will be applied to these newly created files.
It is important to ensure that log files have the correct permissions to ensure that sensitive data is archived and protected.
Edit the /etc/rsyslog.conf and /etc/rsyslog.d/*.conf files and set every instance of $FileCreateMode to 0640 or more restrictive:
$FileCreateMode 0640
| OR |
|
References:
CIS Controls V7.0:
The rsyslog utility supports the ability to send logs it gathers to a remote log host running syslogd(8) or to receive messages from remote hosts, reducing administrative overhead.
Storing log data on a remote host protects log integrity from local attacks. If an attacker gains root access on the local system, they could tamper with or remove log data that is stored on the local system
Note: Ensure that the selection of logfiles being sent follows local site policy
Edit the /etc/rsyslog.conf and /etc/rsyslog.d/*.conf files and add one of the following lines:
Newer syntax:
<files to sent to the remote log server> action(type="omfwd" target="<FQDN or ip of
loghost>" port="<port number>" protocol="tcp"
action.resumeRetryCount="<number of re-tries>"
queue.type="LinkedList" queue.size=<number
of messages to queue>")
Example:
*.* action(type="omfwd" target="192.168.2.100" port="514" protocol="tcp"
action.resumeRetryCount="100"
queue.type="LinkedList" queue.size="1000")
Older syntax:
*.* @@<FQDN or ip of loghost>
Example:
*.* @@192.168.2.100
Run the following command to reload the rsyslog configuration:
# systemctl restart rsyslog
| OR |
|
References:
CIS Controls V7.0:
systemd-journald is a system service that collects and stores logging data. It creates and maintains structured, indexed journals based on logging information that is received from a variety of sources: Kernel log messages, via kmsg
Any changes made to the systemd-journald configuration will require a re-start of systemd-journald
Data from journald may be stored in volatile memory or persisted locally on the server. Utilities exist to accept remote export of journald logs, however, use of the rsyslog service provides a consistent means of log collection and export.
Notes:
Storing log data on a remote host protects log integrity from local attacks. If an attacker gains root access on the local system, they could tamper with or remove log data that is stored on the local system.
Edit the /etc/systemd/journald.conf file and add the following line:
ForwardToSyslog=yes
| AND |
|
References:
CIS Controls V7.0:
The journald system includes the capability of compressing overly large files to avoid filling up the system with logs or making the logs unmanageably large.
Note: The main configuration file /etc/systemd/journald.conf is read before any of the custom *.conf files. If there are custom configs present, they override the main configuration parameters
Uncompressed large files may unexpectedly fill a filesystem leading to resource unavailability. Compressing logs prior to write can prevent sudden, unexpected filesystem impacts.
Edit the /etc/systemd/journald.conf file and add the following line:
Compress=yes
| AND |
|
References:
CIS Controls V7.0:
Data from journald may be stored in volatile memory or persisted locally on the server. Logs in memory will be lost upon a system reboot. By persisting logs to local disk on the server they are protected from loss.
Note: The main configuration file /etc/systemd/journald.conf is read before any of the custom *.conf files. If there are custom configs present, they override the main configuration parameters
Writing log data to disk will provide the ability to forensically reconstruct events which may have impacted the operations or security of a system even after a system crash or reboot.
Edit the /etc/systemd/journald.conf file and add the following line:
Storage=persistent
| AND |
|
References:
CIS Controls V7.0:
Log files stored in /var/log/ contain logged information from many services on the system, or on log hosts others as well.
Note: You may also need to change the configuration for your logging software or services for any logs that had incorrect permissions.
It is important to ensure that log files have the correct permissions to ensure that sensitive data is archived and protected.
Run the following commands to set permissions on all existing log files:
find /var/log -type f -exec chmod g-wx,o-rwx "{}" + -o -type d -exec chmod g-w,o-rwx
"{}" +
| AND |
|
References:
CIS Controls V7.0:
cron is a time-based job scheduler used to schedule jobs, commands or shell scripts, to run periodically at fixed times, dates, or intervals.
at provides the ability to execute a command or shell script at a specified date and hour, or after a given interval of time.
Notes:
The cron daemon is used to execute batch jobs on the system.
Note: Other methods, such as systemd timers , exist for scheduling jobs. If another method is used, cron should be removed, and the alternate method should be secured in accordance with local site policy
While there may not be user jobs that need to be run on the system, the system does have maintenance jobs that may include security monitoring that have to run, and cron is used to execute them.
Run the following command to enable and start cron :
# systemctl --now enable cron
| OR |
|
References:
CIS Controls V7.0:
The /etc/crontab file is used by cron to control its own jobs. The commands in this item make sure that root is the user and group owner of the file and that only the owner can access the file.
Note: Other methods, such as systemd timers , exist for scheduling jobs. If another method is used, cron should be removed, and the alternate method should be secured in accordance with local site policy
This file contains information on what system jobs are run by cron. Write access to these files could provide unprivileged users with the ability to elevate their privileges. Read access to these files could provide users with the ability to gain insight on system jobs that run on the system and could provide them a way to gain unauthorized privileged access.
Run the following commands to set ownership and permissions on /etc/crontab :
# chown root:root /etc/crontab
# chmod og-rwx /etc/crontab
| OR |
|
References:
CIS Controls V7.0:
This directory contains system cron jobs that need to run on an hourly basis. The files in this directory cannot be manipulated by the crontab command, but are instead edited by system administrators using a text editor. The commands below restrict read/write and search access to user and group root, preventing regular users from accessing this directory.
Note: Other methods, such as systemd timers , exist for scheduling jobs. If another method is used, cron should be removed, and the alternate method should be secured in accordance with local site policy
Granting write access to this directory for non-privileged users could provide them the means for gaining unauthorized elevated privileges. Granting read access to this directory could give an unprivileged user insight in how to gain elevated privileges or circumvent auditing controls.
Run the following commands to set ownership and permissions on the /etc/cron.hourly directory:
# chown root:root /etc/cron.hourly/
# chmod og-rwx /etc/cron.hourly/
| OR |
|
References:
CIS Controls V7.0:
The /etc/cron.daily directory contains system cron jobs that need to run on a daily basis. The files in this directory cannot be manipulated by the crontab command, but are instead edited by system administrators using a text editor. The commands below restrict read/write and search access to user and group root, preventing regular users from accessing this directory.
Note: Other methods, such as systemd timers , exist for scheduling jobs. If another method is used, cron should be removed, and the alternate method should be secured in accordance with local site policy
Granting write access to this directory for non-privileged users could provide them the means for gaining unauthorized elevated privileges. Granting read access to this directory could give an unprivileged user insight in how to gain elevated privileges or circumvent auditing controls.
Run the following commands to set ownership and permissions on the /etc/cron.daily directory:
# chown root:root /etc/cron.daily/
# chmod og-rwx /etc/cron.daily/
| OR |
|
References:
CIS Controls V7.0:
The /etc/cron.weekly directory contains system cron jobs that need to run on a weekly basis. The files in this directory cannot be manipulated by the crontab command, but are instead edited by system administrators using a text editor. The commands below restrict read/write and search access to user and group root, preventing regular users from accessing this directory.
Note: Other methods, such as systemd timers , exist for scheduling jobs. If another method is used, cron should be removed, and the alternate method should be secured in accordance with local site policy
Granting write access to this directory for non-privileged users could provide them the means for gaining unauthorized elevated privileges. Granting read access to this directory could give an unprivileged user insight in how to gain elevated privileges or circumvent auditing controls.
Run the following commands to set ownership and permissions on the /etc/cron.weekly directory:
# chown root:root /etc/cron.weekly/
# chmod og-rwx /etc/cron.weekly/
| OR |
|
References:
CIS Controls V7.0:
The /etc/cron.monthly directory contains system cron jobs that need to run on a monthly basis. The files in this directory cannot be manipulated by the crontab command, but are instead edited by system administrators using a text editor. The commands below restrict read/write and search access to user and group root, preventing regular users from accessing this directory.
Note: Other methods, such as systemd timers , exist for scheduling jobs. If another method is used, cron should be removed, and the alternate method should be secured in accordance with local site policy
Granting write access to this directory for non-privileged users could provide them the means for gaining unauthorized elevated privileges. Granting read access to this directory could give an unprivileged user insight in how to gain elevated privileges or circumvent auditing controls.
Run the following commands to set ownership and permissions on the /etc/cron.monthly directory:
# chown root:root /etc/cron.monthly/
# chmod og-rwx /etc/cron.monthly/
| OR |
|
References:
CIS Controls V7.0:
The /etc/cron.d directory contains system cron jobs that need to run in a similar manner to the hourly, daily weekly and monthly jobs from /etc/crontab , but require more granular control as to when they run. The files in this directory cannot be manipulated by the crontab command, but are instead edited by system administrators using a text editor. The commands below restrict read/write and search access to user and group root, preventing regular users from accessing this directory.
Note: Other methods, such as systemd timers , exist for scheduling jobs. If another method is used, cron should be removed, and the alternate method should be secured in accordance with local site policy
Granting write access to this directory for non-privileged users could provide them the means for gaining unauthorized elevated privileges. Granting read access to this directory could give an unprivileged user insight in how to gain elevated privileges or circumvent auditing controls.
Run the following commands to set ownership and permissions on the /etc/cron.d directory:
# chown root:root /etc/cron.d/
# chmod og-rwx /etc/cron.d/
| OR |
|
References:
CIS Controls V7.0:
Configure /etc/cron.allow to allow specific users to use this service. If /etc/cron.allow does not exist, then /etc/cron.deny is checked. Any user not specifically defined in this file is allowed to use cron. By removing the file, only users in /etc/cron.allow are allowed to use cron.
Notes:
On many systems, only the system administrator is authorized to schedule cron jobs. Using the cron.allow file to control who can run cron jobs enforces this policy. It is easier to manage an allow list than a deny list. In a deny list, you could potentially add a user ID to the system and forget to add it to the deny files.
Run the following commands to remove /etc/cron.deny :
# rm /etc/cron.deny
Run the following command to create /etc/cron.allow
# touch /etc/cron.allow
Run the following commands to set permissions and ownership for /etc/cron.allow :
# chmod g-wx,o-rwx /etc/cron.allow
# chown root:root /etc/cron.allow
| OR |
|
References:
CIS Controls V7.0:
sudo allows a permitted user to execute a command as the superuser or another user, as specified by the security policy. The invoking user's real (not effective) user ID is used to determine the user name with which to query the security policy.
sudo supports a plugin architecture for security policies and input/output logging. Third parties can develop and distribute their own policy and I/O logging plugins to work seamlessly with the sudo front end. The default security policy is sudoers, which is configured via the file /etc/sudoers.
sudo can be configured to run only from a pseudo-pty
Note: visudo edits the sudoers file in a safe fashion, analogous to vipw(8). visudo locks the sudoers file against multiple simultaneous edits, provides basic sanity checks, and checks or parse errors. If the sudoers file is currently being edited you will receive a message to try again later.
Attackers can run a malicious program using sudo, which would again fork a background process that remains even when the main program has finished executing.
Edit the file /etc/sudoers or a file in /etc/sudoers.d/ with visudo -f and add the following line:
Defaults use_pty
| OR |
|
References:
CIS Controls V7.0:
sudo can use a custom log file.
Note: visudo edits the sudoers file in a safe fashion, analogous to vipw(8). visudo locks the sudoers file against multiple simultaneous edits, provides basic sanity checks, and checks or parse errors. If the sudoers file is currently being edited you will receive a message to try again later.
A sudo log file simplifies auditing of sudo commands
Edit the file /etc/sudoers or a file in /etc/sudoers.d/ with visudo -f and add the following line: and add the following line:
Defaults logfile="<PATH TO CUSTOM LOG FILE>"
Example:
Defaults logfile="/var/log/sudo.log"
| OR |
|
References:
CIS Controls V7.0:
SSH is a secure, encrypted replacement for common login services such as telnet , ftp , rlogin , rsh , and rcp . It is strongly recommended that sites abandon older clear-text login protocols and use SSH to prevent session hijacking and sniffing of sensitive data off the network.
Note:
# apt purge openssh-server
# systemctl reload sshd
The /etc/ssh/sshd_config file contains configuration specifications for sshd . The command below sets the owner and group of the file to root.
The /etc/ssh/sshd_config file needs to be protected from unauthorized changes by non-privileged users.
Run the following commands to set ownership and permissions on /etc/ssh/sshd_config :
# chown root:root /etc/ssh/sshd_config
# chmod og-rwx /etc/ssh/sshd_config
| OR |
|
References:
CIS Controls V7.0:
There are several options available to limit which users and group can access the system via SSH. It is recommended that at least one of the following options be leveraged:
Restricting which users can remotely access the system via SSH will help ensure that only authorized users access the system.
Edit the /etc/ssh/sshd_config file to set one or more of the parameter as follows:
AllowUsers <userlist>
OR
AllowGroups <grouplist>
OR
DenyUsers <userlist>
OR
DenyGroups <grouplist>
| OR |
|
References:
CIS Controls V7.0:
The MaxAuthTries parameter specifies the maximum number of authentication attempts permitted per connection. When the login failure count reaches half the number, error messages will be written to the syslog file detailing the login failure.
Setting the MaxAuthTries parameter to a low number will minimize the risk of successful brute force attacks to the SSH server. While the recommended setting is 4, set the number based on site policy.
Edit the /etc/ssh/sshd_config file to set the parameter as follows:
MaxAuthTries 4
| OR |
|
References:
CIS Controls V7.0:
The PermitRootLogin parameter specifies if the root user can log in using ssh. The default is no.
Disallowing root logins over SSH requires system admins to authenticate using their own individual account, then escalating to root via sudo . This in turn limits opportunity for non-repudiation and provides a clear audit trail in the event of a security incident
Edit the /etc/ssh/sshd_config file to set the parameter as follows:
PermitRootLogin no
| OR |
|
References:
CIS Controls V7.0:
This variable Specifies the available MAC (message authentication code) algorithms. The MAC algorithm is used in protocol version 2 for data integrity protection. Multiple algorithms must be comma-separated.
MD5 and 96-bit MAC algorithms are considered weak and have been shown to increase exploitability in SSH downgrade attacks. Weak algorithms continue to have a great deal of attention as a weak spot that can be exploited with expanded computing power. An attacker that breaks the algorithm could take advantage of a MiTM position to decrypt the SSH tunnel and capture credentials and information
Edit the /etc/ssh/sshd_config file and add/modify the MACs line to contain a comma separated list of the site approved MACs
Example:
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512,hmac-sha2-256
| OR |
|
References:
CIS Controls V7.0:
Key exchange is any method in cryptography by which cryptographic keys are exchanged between two parties, allowing use of a cryptographic algorithm. If the sender and receiver wish to exchange encrypted messages, each must be equipped to encrypt messages to be sent and decrypt messages received
Key exchange methods that are considered weak should be removed. A key exchange method may be weak because too few bits are used or the hashing algorithm is considered too weak. Using weak algorithms could expose connections to man-in-the-middle attacks
Edit the /etc/ssh/sshd_config file add/modify the KexAlgorithms line to contain a comma separated list of the site approved key exchange algorithms
Example:
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256
| OR |
|
References:
CIS Controls V7.0:
The two options ClientAliveInterval and ClientAliveCountMax control the timeout of ssh sessions.
Example: The default value is 3. If ClientAliveInterval is set to 15, and ClientAliveCountMax is left at the default, unresponsive SSH clients will be disconnected after approximately 45 seconds
Having no timeout value associated with a connection could allow an unauthorized user access to another user's ssh session (e.g. user walks away from their computer and doesn't lock the screen). Setting a timeout value reduces this risk.
Edit the /etc/ssh/sshd_config file to set the parameters according to site policy. This should include ClientAliveInterval between 1 and 900 and ClientAliveCountMax of 0 :
ClientAliveInterval 900
ClientAliveCountMax 0
Impact:
In some cases this setting may cause termination of long-running scripts over SSH or remote automation tools which rely on SSH. In developing the local site policy, the requirements of such scripts should be considered and appropriate ServerAliveInterval and ClientAliveInterval settings should be calculated to insure operational continuity.
| OR |
|
References:
CIS Controls V7.0:
The LoginGraceTime parameter specifies the time allowed for successful authentication to the SSH server. The longer the Grace period is the more open unauthenticated connections can exist. Like other session controls in this session the Grace Period should be limited to appropriate organizational limits to ensure the service is available for needed access.
Setting the LoginGraceTime parameter to a low number will minimize the risk of successful brute force attacks to the SSH server. It will also limit the number of concurrent unauthenticated connections While the recommended setting is 60 seconds (1 Minute), set the number based on site policy.
Edit the /etc/ssh/sshd_config file to set the parameter as follows:
LoginGraceTime 60
| OR |
|
References:
CIS Controls V7.0:
The Banner parameter specifies a file whose contents must be sent to the remote user before authentication is permitted. By default, no banner is displayed.
Banners are used to warn connecting users of the particular site's policy regarding connection. Presenting a warning message prior to the normal user login may assist the prosecution of trespassers on the computer system.
Edit the /etc/ssh/sshd_config file to set the parameter as follows:
Banner /etc/issue.net
| OR |
|
References:
CIS Controls V7.0:
The MaxStartups parameter specifies the maximum number of concurrent unauthenticated connections to the SSH daemon.
To protect a system from denial of service due to a large number of pending authentication connection attempts, use the rate limiting function of MaxStartups to protect availability of sshd logins and prevent overwhelming the daemon.
Edit the /etc/ssh/sshd_config file to set the parameter as follows:
maxstartups 10:30:60
| OR |
|
References:
CIS Controls V7.0:
PAM (Pluggable Authentication Modules) is a service that implements modular authentication modules on UNIX systems. PAM is implemented as a set of shared objects that are loaded and executed when a program needs to authenticate a user. Files for PAM are typically located in the /etc/pam.d directory. PAM must be carefully configured to secure system authentication. While this section covers some of PAM, please consult other PAM resources to fully understand the configuration capabilities.
The pam_pwquality.so module checks the strength of passwords. It performs checks such as making sure a password is not a dictionary word, it is a certain length, contains a mix of characters (e.g. alphabet, numeric, other) and more. The following are definitions of the pam_pwquality.so options.
The following options are set in the /etc/security/pwquality.conf file:
minclass = 4 - The minimum number of required classes of characters for the new password (digits, uppercase, lowercase, others)
OR
dcredit = -1 - provide at least one digit
ucredit = -1 - provide at least one uppercase character
ocredit = -1 - provide at least one special character
lcredit = -1 - provide at least one lowercase character
The following is st in the /etc/pam.d/common-password file:
Strong passwords protect systems from being hacked through brute force methods.
Run the following command to install the pam_pwquality module:
apt install libpam-pwquality
Edit the file /etc/security/pwquality.conf and add or modify the following line for password length to conform to site policy
minlen = 14
Edit the file /etc/security/pwquality.conf and add or modify the following line for password complexity to conform to site policy
minclass = 4
OR
dcredit = -1
ucredit = -1
ocredit = -1
lcredit = -1
Edit the /etc/pam.d/common-password file to include the appropriate options for pam_pwquality.so and to conform to site policy:
password requisite pam_pwquality.so retry=3
| AND |
|
References:
CIS Controls V7.0:
Lock out users after n unsuccessful consecutive login attempts. The first sets of changes are made to the PAM configuration files. The second set of changes are applied to the program specific PAM configuration file. The second set of changes must be applied to each program that will lock out users. Check the documentation for each secondary program for instructions on how to configure them to work with PAM.
Locking out user IDs after n unsuccessful consecutive login attempts mitigates brute force password attacks against your systems.
Edit the /etc/pam.d/common-auth file and add the auth line below:
auth required pam_tally2.so onerr=fail audit silent deny=5 unlock_time=900
Edit the /etc/pam.d/common-account file and add the account lines bellow:
account requisite pam_deny.so
account required pam_tally2.so
| AND |
|
References:
CIS Controls V7.0:
The /etc/security/opasswd file stores the users' old passwords and can be checked to ensure that users are not recycling recent passwords.
Forcing users not to reuse their past 5 passwords make it less likely that an attacker will be able to guess the password.
Edit the /etc/pam.d/common-password file to include the remember option and conform to site policy as shown:
password required pam_pwhistory.so remember=5
| AND |
|
References:
CIS Controls V7.0:
This section provides guidance on setting up secure defaults for system and user accounts and their environment.
While a majority of the password control parameters have been moved to PAM, some parameters are still available through the shadow password suite. Any changes made to /etc/login.defs will only be applied if the usermod command is used. If user IDs are added a different way, use the chage command to effect changes to individual user IDs.
The PASS_MIN_DAYS parameter in /etc/login.defs allows an administrator to prevent users from changing their password until a minimum number of days have passed since the last time the user changed their password. It is recommended that PASS_MIN_DAYS parameter be set to 1 or more days.
By restricting the frequency of password changes, an administrator can prevent users from repeatedly changing their password in an attempt to circumvent password reuse controls.
Set the PASS_MIN_DAYS parameter to 1 in /etc/login.defs :
PASS_MIN_DAYS 1
Modify user parameters for all users with a password set to match:
# chage --mindays 1 <user>
| AND |
|
References:
CIS Controls V7.0:
The PASS_MAX_DAYS parameter in /etc/login.defs allows an administrator to force passwords to expire once they reach a defined age.
The window of opportunity for an attacker to leverage compromised credentials or successfully compromise credentials via an online brute force attack is limited by the age of the password. Therefore, reducing the maximum age of a password also reduces an attacker's window of opportunity. It is recommended that the PASS_MAX_DAYS parameter does not exceed 365 days and is greater than the value of PASS_MIN_DAYS .
Set the PASS_MAX_DAYS parameter to conform to site policy in /etc/login.defs :
PASS_MAX_DAYS 365
Modify user parameters for all users with a password set to match:
# chage --maxdays 365 <user>
| AND |
|
References:
CIS Controls V7.0:
User accounts that have been inactive for over a given period of time can be automatically disabled. It is recommended that accounts that are inactive for 30 days after password expiration be disabled.
Inactive accounts pose a threat to system security since the users are not logging in to notice failed login attempts or other anomalies.
Run the following command to set the default password inactivity period to 30 days:
# useradd -D -f 30
Modify user parameters for all users with a password set to match:
# chage --inactive 30 <user>
| AND |
|
References:
CIS Controls V7.0:
The user file-creation mode mask ( umask ) is use to determine the file permission for newly created directories and files. In Linux, the default permissions for any newly created directory is 0777 (rwxrwxrwx), and for any newly created file it is 0666 (rw-rw-rw-). The umask modifies the default Linux permissions by restricting (masking) these permissions. The umask is not simply subtracted, but is processed bitwise. Bits set in the umask are cleared in the resulting file mode.
umask can be set with either octal or Symbolic values
Setting the default umask :
User Shell Configuration Files:
Setting a very secure default value for umask ensures that users make a conscious choice about their file permissions. A default umask setting of 077 causes files and directories created by users to not be readable by any other user on the system. A umask of 027 would make files and directories readable by users in the same Unix group, while a umask of 022 would make files readable by every user on the system.
Run the following command and remove or modify the umask of any returned files:
# grep -RPi '(^|^[^#]*)\s*umask\s+([0-7][0-7][01][0-7]\b|[0-7][0-7][0-7][0-6]\b|[0-7][01][0-7]\b|[0-7][0-7][0-6]\b|(u=[rwx]{0,3},)?(g=[rwx]{0,3},)?o=[rwx]+\b|(u=[rwx]{1,3},)?g=[^rx]{1,3}(,o=[rwx]{0,3})?\b)'
/etc/login.defs /etc/profile* /etc/bash.bashrc*
Follow one of the following methods to set the default user umask:
Edit /etc/login.defs and edit the UMASK and USERGROUPS_ENAB lines as follows:
UMASK 027
USERGROUPS_ENAB no
Edit /etc/pam.d/common-session and add or edit the following:
session optional pam_umask.so
OR
Configure umask in one of the following files:
Example: /etc/profile.d/set_umask.sh
umask 027
Note: this method only applies to bash and shell. If other shells are supported on the system, it is recommended that their configuration files also are checked.
Impact:
Setting USERGROUPS_ENAB no in /etc/login.defs may change the expected behavior of useradd and userdel .
Setting USERGROUPS_ENAB yes in /etc/login.defs
| AND |
|
References:
CIS Controls V7.0:
TMOUT is an environmental setting that determines the timeout of a shell in seconds.
System Wide Shell Configuration Files:
Setting a timeout value reduces the window of opportunity for unauthorized user access to another user's shell session that has been left unattended. It also ends the inactive session and releases the resources associated with that session.
Review /etc/bash.bashrc , /etc/profile , and all files ending in *.sh in the /etc/profile.d/ directory and remove or edit all TMOUT=_n_ entries to follow local site policy. TMOUT should not exceed 900 or be equal to 0 .
Configure TMOUT in one of the following files:
TMOUT configuration examples:
TMOUT=900
readonly TMOUT
export TMOUT
readonly TMOUT=900 ; export TMOUT
| AND |
|
References:
CIS Controls V7.0:
The su command allows a user to run a command or shell as another user. The program has been superseded by sudo , which allows for more granular control over privileged access. Normally, the su command can be executed by any user. By adding, or uncommenting, the pam_wheel.so statement in /etc/pam.d/su , the su command will only allow users in a specific group to execute su . This group should be empty to reinforce the use of sudo for privileged access.
Restricting the use of su , and using sudo in its place, provides system administrators better control of the escalation of user privileges to execute privileged commands. The sudo utility also provides a better logging and audit mechanism, as it can log each command executed via sudo , whereas su can only record that a user executed the su program.
Create an empty group that will be specified for use of the su command. The group should be named according to site policy.
Example:
# groupadd sugroup
Add the following line to the /etc/pam.d/su file, specifying the empty group:
Example:
auth required pam_wheel.so use_uid group=sugroup
| AND |
|
References:
CIS Controls V7.0:
Recommendations in this section are intended as maintenance and are intended to be checked on a frequent basis to ensure system stability. Many recommendations do not have quick remediations and require investigation into the cause and best fix available and may indicate an attempted breach of system security.
This section provides guidance on securing aspects of system files and directories.
Unix-based systems support variable settings to control access to files. World writable files are the least secure. See the chmod(2) man page for more information.
Data in world-writable files can be modified and compromised by any user on the system. World writable files may also indicate an incorrectly written script or program that could potentially be the cause of a larger compromise to the system's integrity.
Removing write access for the "other" category ( chmod o-w <filename> ) is advisable, but always consult relevant vendor documentation to avoid breaking any application dependencies on a given file.
| AND |
|
References:
CIS Controls V7.0:
This section provides guidance on securing aspects of the users and groups.
Note: The recommendations in this section check local users and groups. Any users or groups from other sources such as LDAP will not be audited. In a domain environment similar checks should be performed against domain users and groups.
Users can be defined in /etc/passwd without a home directory or with a home directory that does not actually exist.
Note: The audit script checks all users with interactive shells except halt , sync , shutdown , and nfsnobody
If the user's home directory does not exist or is unassigned, the user will be placed in "/" and will not be able to write any files or have local environment variables set.
If any users' home directories do not exist, create them and make sure the respective user owns the directory. Users without an assigned home directory should be removed or assigned a home directory as appropriate.
The following script will create a home directory for users with an interactive shell whose home directory doesn't exist:
#!/bin/bash
awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/
&& $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read
-r user dir; do
if [ ! -d "$dir" ]; then
mkdir "$dir"
chmod g-w,o-wrx "$dir"
chown "$user" "$dir"
fi
done
| AND |
|
References:
CIS Controls V7.0:
While the system administrator can establish secure permissions for users' home directories, the users can easily override these.
Group or world-writable user home directories may enable malicious users to steal or modify other users' data or to gain another user's system privileges.
Making global modifications to user home directories without alerting the user community can result in unexpected outages and unhappy users. Therefore, it is recommended that a monitoring policy be established to report user file permissions and determine the action to be taken in accordance with site policy.
The following script can be used to remove permissions is excess of 750 from users' home directories:
#!/bin/bash
awk -F: '($1!~/(halt|sync|shutdown)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/)
{print $6}' /etc/passwd | while read -r dir; do
if [ -d "$dir" ]; then
dirperm=$(stat -L -c "%A" "$dir")
if [ "$(echo "$dirperm" | cut -c6)" != "-" ] || [ "$(echo "$dirperm" | cut -c8)" !=
"-" ] || [ "$(echo "$dirperm" | cut -c9)" != "-" ] || [ "$(echo "$dirperm" | cut -c10)"
!= "-" ]; then
chmod g-w,o-rwx "$dir"
fi
fi
done
| AND |
|
References:
CIS Controls V7.0: